package com.baymax.test.scene.demo

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.graphics.ColorUtils
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.badlogic.gdx.graphics.Color

/**
 * @title:       标题
 * @project:     TestScene
 * @package:     com.baymax.test.scene.demo
 * @class:       FragmentHolder
 * @description:
 * <p>
 * 类描述
 * </p>
 *
 * @version:   1.0
 * @createDate:   2023/3/8 10:17
 * @Copyright (C) 2023 YSTEN
 * @author:       xuyujian
 */
class FragmentHolder() : Fragment() {
    private val tagstr: String by  lazy { arguments?.getString("tagStr").orEmpty() }
    private val index: Int by  lazy { arguments?.getInt("position") ?: -1 }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = TextView(inflater.context).apply {
        text = "$tagstr:$index"
        minWidth = 600
        minHeight = 600
        gravity = Gravity.CENTER
    }
}

class ViewPagerFragmentHolder() : Fragment() {
    val parentPos by lazy { arguments?.getInt("position") ?: -1 }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = ViewPager(inflater.context).apply {
//        setBackgroundColor(
//            ColorUtils.setAlphaComponent(android.graphics.Color.RED,
//                ((parentPos/10f ) *255).toInt()
//            )
//        )
        id = View.generateViewId()
        adapter = object : FragmentStatePagerAdapter(childFragmentManager) {
            override fun getCount(): Int = 3

            override fun getItem(position: Int): Fragment {
                return FragmentHolder().apply {
                    arguments = bundleOf("tagStr" to "ViewPagerFragmentHolder[$parentPos]" ,"position" to position)
                }

            }

        }

    }
}